<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../node_modules/axios/dist/axios.min.js"></script>
</head>
<body>
  
    <button>开始请求</button>
    <button>取消请求</button>
   
    <script>
        let btn = document.querySelectorAll('button')
        let cancel = null;
        btn[0].addEventListener('click', ()=>{
            axios('http://api.liu.com:3000/students',{
                cancelToken:new axios.CancelToken(cb=>{
                    cancel = cb;
                })
            })
        })
        btn[1].addEventListener('click',()=>{
            if(cancel){
                cancel()
            }
        })

        
    </script>

</body>
</html>